package com.company.model;

import com.company.db.DBProvide;
import com.company.util.Myutils;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.util.List;
import java.util.Map;

public class UserModel {

    /**
     * 验证用户是否登录成功
     * @param userName
     * @param userPsw
     * @return
     */

    public boolean doLogin(String userName, String  userPsw){
        //默认返回值
        boolean canLogined = false;

        //验证是否有这个人，即从数据库中查询
        //查询sql语句
        String strSql =
                " SELECT * FROM userinfo WHERE userName = ? AND userPsw = ?";

        //创建查询器的对象
        //DBProvider dbProvider = new DBProvider();
       // List<Map<String,Object>> list = dbProvider.queryListMap(strSql,userName,userPsw);

        List<Map<String,Object>> list = Myutils.getNewIntance(DBProvide.class).
                query(strSql,new MapListHandler(),userName,userPsw);

        //判断是否登录成功
        if (list!=null && list.size()>0){
            //登录成功
            canLogined = true;
        }
        //返回值
        return canLogined;
    }
}
